<%-- 
    Document   : showbook
    Created on : 2015-6-26, 14:33:55
    Author     : MY
--%>

<%@page import="bookstore.model.Book"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>ShowBookss</title>
        <link rel="stylesheet" href="/iBook/css/all.css" type="text/css"/>
        <link rel="stylesheet" href="/iBook/css/bootstrap.min.css" type="text/css"/>
    </head>
    <body>
        <jsp:include  page="/common/top.jsp"/>
        <div class="container">
            <div class="row">
                <%
                    List<Book> list = (List<Book>) session.getAttribute("bookList");
                    for (int i = 0; i < list.size(); ++i) {
                        Book book = list.get(i);

                %>    
                <div class="col-sm-2 col-md-2">
                    <div class="thumbnail" style="width: 160px;height: 280px">
                        <a href="/iBook/book/bookDetails.jsp?list_index=<%=i %>">
                        <img src="/iBook/bookimages/<%=book.getPicture()%>" alt="..." style="display:block;width:70%;height: 60%;  ">
                        </a>
                        <div class="caption" >
                            <a href="/iBook/book/bookDetails.jsp?list_index=<%=i %>"><center><h5><%=book.getName()%></h3></center></a>
                            <div style="margin-bottom:5px"><center><p ><strong><%=book.getPrice()%>￥</strong></p></center></div>
                        </div>
                    </div>
                </div>


                <%;
                }%>
            </div>
            <center>
                <%
                    int pageNo = Integer.parseInt(session.getAttribute("pageNo").toString());
                    int prePage = pageNo - 1;
                    int nextPage = pageNo + 1;
                    String cla = "";
                    if(pageNo == 1)
                    {
                        prePage = 1;
                        cla = "disabled";
                    }
                    if(list.size() == 0)
                    {%>
                    <nav >
                        <ul class="pagination"> 
                            <li>
                                <a href="BookAction.action?pageNo=<%=prePage%>&categoryId=<%=request.getParameter("categoryId")%>" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                            </li>
                            <li ><a href="BookAction.action?pageNo=<%=pageNo-1%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo-1%></a></li>
                            <li class="active"><a href="BookAction.action?pageNo=<%=pageNo%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo%></a></li>
                        </ul>
                    </nav>
                    <%}
                    else{
                    if(pageNo <=3)
                    {
                %>
                <nav >
                    <ul class="pagination">         
                        <li class="<%=cla%>">
                            <a href="BookAction.action?pageNo=<%=prePage%>&categoryId=<%=request.getParameter("categoryId")%>" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <% for(int i=0;i<5;i++)
                        {
                            if(i+1 == pageNo)
                            {%>
                            <li class="active"><a href="BookAction.action?pageNo=<%=i+1%>&categoryId=<%=request.getParameter("categoryId")%>"><%=i+1%></a></li>
                            <%}
                            else{
                                %>
                            <li><a href="BookAction.action?pageNo=<%=i+1%>&categoryId=<%=request.getParameter("categoryId")%>"><%=i+1%></a></li>
                        <%}}%>
                            <li>
                            <a href="BookAction.action?pageNo=<%=nextPage%>&categoryId=<%=request.getParameter("categoryId")%>" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
                 <%}
                    else{
                        %>
                        <nav >
                    <ul class="pagination">
                        <li>
                            <a href="BookAction.action?pageNo=<%=prePage%>&categoryId=<%=request.getParameter("categoryId")%>" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li><a href="BookAction.action?pageNo=<%=pageNo-2%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo-2%></a></li>
                        <li><a href="BookAction.action?pageNo=<%=pageNo-1%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo-1%></a></li>
                        <li class="active"><a href="BookAction.action?pageNo=<%=pageNo%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo%></a></li>
                        <li><a href="BookAction.action?pageNo=<%=pageNo+1%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo+1%></a></li>
                        <li><a href="BookAction.action?pageNo=<%=pageNo+2%>&categoryId=<%=request.getParameter("categoryId")%>"><%=pageNo+2%></a></li>
                        <li>
                            <a href="BookAction.action?pageNo=<%=nextPage%>&categoryId=<%=request.getParameter("categoryId")%>" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
                    <%}}%>
            </center>
            <jsp:include  page="/common/bottom.jsp"/>
    </body>
</html>
